import {
  onUpdated,
  ref
} from 'vue'

export const calcTableHeight = (height) => {

  const tableRef = ref(null)

  let tableHeight = ref(300)

  const table = () => {
    if (tableRef.value) {
      setTimeout(() => {
        if (height) {
          tableHeight.value = height
        } else {
          if (tableRef.value) {
            tableHeight.value = window.innerHeight - tableRef.value.$el.offsetTop - 66
          }
        }
      }, 10)
    }
  }

  onUpdated(() => {
    table()
    window.addEventListener('resize', table)
  })

  return {
    tableRef,
    tableHeight
  }
}
